import QtQuick 1.1
import com.nokia.meego 1.0
import "Logic.js" as Logic

Page {
    id: qnm_mainPage
    orientationLock: appWindow.lockOrientation()

    signal quitMyApp
    signal openWinSettings

    tools: ToolBarLayout {
        id: tool_main_page
        visible: true
        ToolIcon {
            iconId: "toolbar-view-menu"
            anchors.right: parent === undefined ? undefined : parent.right
            onClicked: (qnm_MenuMainPage.status == DialogStatus.Closed) ? qnm_MenuMainPage.open() : qnm_MenuMainPage.close()
        }
    }

    onVisibleChanged: {
        if( visible && firstStart ) {
            animFirstRun.running = true
            firstStart = false
        }
    }

    SequentialAnimation {
        id: animFirstRun
        running: false
        //PauseAnimation { duration: 200 }
        ParallelAnimation {
            NumberAnimation { target: pB_WiFiMonitor; property: "opacity"; from:0; to:1; duration: 1300; }
            NumberAnimation { target: pB_NetworkConnections; property: "opacity"; from:0; to:1; duration: 1300; }
            NumberAnimation { target: pB_MonitorConnections; property: "opacity"; from:0; to:1; duration: 1300; }
            NumberAnimation { target: pB_Settings; property: "opacity"; from:0; to:1; duration: 1300; }
        }
    }


    Menu {
        id: qnm_MenuMainPage
        visualParent: pageStack
        MenuLayout {
            MenuItem { text: qsTr("About") + cppLanguage.forceLanguage; onClicked: { qnm_mainPage.openFile("About.qml") } }
            MenuItem { text: qsTr("Donate") + cppLanguage.forceLanguage; onClicked: { dlgDonate.open() } }
            MenuItem { text: qsTr("Quit") + cppLanguage.forceLanguage; onClicked: { cppQNetMan.quitQNetMan() } }
        }
    }

    function openFile(file) {
        var component = Qt.createComponent(file)
        if (component.status == Component.Ready)
            pageStack.push(component);
        else
            console.log("Error loading component:", component.errorString());
    }

    BackgroundPage { }


    Item {
        id: mainPane
        anchors.centerIn: parent
        width: parent.width
        height: parent.height

        MyMainButton {
            id: pB_WiFiMonitor
            width: parent.width/2
            height: parent.height/2
            anchors.top: parent.top
            anchors.left: parent.left
            textButtonSize: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 18 : 22
            image: "./pictures/wireless.png"
            textButton: qsTr("WiFi") + cppLanguage.forceLanguage
            onButtonClick: {
                qnm_mainPage.openFile("WiFiMonitorPage.qml");
            }
            opacity: 0
        }

        MyMainButton {
            id: pB_MonitorConnections
            width: parent.width/2
            height: parent.height/2
            anchors.top: parent.top
            anchors.left: pB_WiFiMonitor.right
            textButtonSize: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 18 : 22
            image: "./pictures/realtime.png"
            textButton: qsTr("Monitor") + cppLanguage.forceLanguage
            onButtonClick: {
                qnm_mainPage.openFile("MyMonitor.qml");
            }
            opacity: 0
        }

        MyMainButton {
            id: pB_NetworkConnections
            width: parent.width/2
            height: parent.height/2
            anchors.top: pB_WiFiMonitor.bottom
            anchors.left: parent.left
            textButtonSize: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 18 : 22
            textButton: qsTr("Connections") + cppLanguage.forceLanguage
            image: "./pictures/connections.png"
            onButtonClick: {
                qnm_mainPage.openFile("NetworkConnections.qml")
                cppNetStat.initData()
            }
            opacity: 0
        }

        MyMainButton {
            id: pB_Settings
            width: parent.width/2
            height: parent.height/2
            anchors.top: pB_MonitorConnections.bottom
            anchors.right: parent.right
            textButtonSize: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 18 : 22
            textButton: qsTr("Settings") + cppLanguage.forceLanguage
            image: "./pictures/options.png"
            onButtonClick: {
                qnm_mainPage.openFile("Settings.qml")
            }
            opacity: 0
        }

    } //Item

    QueryDialog {
        id: dlgDonate
        content: Item {
            anchors.horizontalCenter: parent.horizontalCenter
            height: 200
            Image {
                id: imgPayPal
                anchors.centerIn: parent
                z: 10
                smooth: true
                scale: 1.7
                source: "pictures/btn_donateCC_LG.png"
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        Qt.openUrlExternally( "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=qnetworkmanager%40gmail%2ecom&lc=RU&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" )
                    }
                }
            }
        }

        buttons: Button {
            text: "Ok"
            onClicked: dlgDonate.close()
            platformStyle: ButtonStyle { inverted: true }
            anchors.horizontalCenter: parent.horizontalCenter
        }
    }

}
